package com.wkhyapp.lm.contract;

import com.wkhyapp.lm.base.BasePresenter;
import com.wkhyapp.lm.http.ApiCallback;
import com.wkhyapp.lm.http.net.BaseRequest;
import com.wkhyapp.lm.http.net.MemberListRequest;
import com.wkhyapp.lm.http.net.SuperResponse;
import com.wkhyapp.lm.http.vo.Banner;
import com.wkhyapp.lm.http.vo.Member;

/**
 * Created by Administrator on 2021-10-1.
 */

public class IndexPagesPresenter extends BasePresenter<IndexPagesView> {

    public IndexPagesPresenter(IndexPagesView indexPagesView) {
        super(indexPagesView);
    }


    public void  getBanner(){
        MemberListRequest request  = new MemberListRequest();
        addSubscription(apiStores.banners(request),new ApiCallback<SuperResponse<Banner>>() {
            @Override
            public void onSuccess(SuperResponse<Banner> response) {
                mvpView.setBanner(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
                mvpView.setfail(msg);
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void  getNewlySettled(){
        BaseRequest request  = new BaseRequest();
        addSubscription(apiStores.newlySettled(request),new ApiCallback<SuperResponse<Member>>() {
            @Override
            public void onSuccess(SuperResponse<Member> response) {
                mvpView.setNewlySettled(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
                mvpView.setfail(msg);
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }

    public void  getMember(Integer category,Integer pageNo,Integer pageSize){
        MemberListRequest request  = new MemberListRequest();
        request.setCategoryId(category);
        request.setPageNo(1);
        request.setPageSize(pageSize);
        addSubscription(apiStores.memberList(request),new ApiCallback<SuperResponse<Member>>() {
            @Override
            public void onSuccess(SuperResponse<Member> response) {
                mvpView.setMemberList(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
                mvpView.setfail(msg);
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }



    public void  getMemberMore(Integer category,Integer pageNo,Integer pageSize){
        MemberListRequest request  = new MemberListRequest();
        request.setCategoryId(category);
        request.setPageNo(pageNo);
        request.setPageSize(pageSize);
        addSubscription(apiStores.memberList(request),new ApiCallback<SuperResponse<Member>>() {
            @Override
            public void onSuccess(SuperResponse<Member> response) {
                mvpView.setMemberMore(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
                mvpView.setfail(msg);
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }

    public void  getToken(){
        BaseRequest request = new BaseRequest();
        // request.setUserId(MemberUtils.getUid());
        addSubscription(apiStores.getUploadToken(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.setToken(response.getItem());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
            }
        });
    }
}
